package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.TestQuestionMapper;
import com.ghck.server.model.TestQuestion;
import com.ghck.server.model.query.TestQuestionQuery;
import com.ghck.server.service.TestQuestionService;

/**
 * 测试题  <br>
 * t_test_question <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class TestQuestionServiceImpl implements TestQuestionService {
	
	private static final Logger logger = LoggerFactory.getLogger(TestQuestionServiceImpl.class);
	
	@Autowired
	private TestQuestionMapper testQuestionMapper;
	
	/**
 	*根据ID删除 测试题
 	*/
 	@Override
 	public Integer deleteTestQuestionById(Integer id){
 		return testQuestionMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 测试题
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertTestQuestion(List<? extends TestQuestion> testQuestions){
		Integer count = testQuestionMapper.batchInsert(testQuestions);
		return count;
 	}
 	/**
 	*新增 测试题
 	*/
 	@Override
 	@Transactional
 	public Integer insertTestQuestion(TestQuestion domain){
		Integer id = testQuestionMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 测试题
 	*/
 	@Override
 	@Transactional
 	public Integer updateTestQuestion(TestQuestion domain){
		Integer count = testQuestionMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 测试题
 	*/
 	public TestQuestion findTestQuestionById(Integer id){
 		TestQuestion result = testQuestionMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 测试题
 	*/
	public List<TestQuestion> findTestQuestionByQuery(TestQuestionQuery query){
		query.dealWith();
		List<TestQuestion> result = testQuestionMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestQuestion testQuestion : result) {
				testQuestion.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countTestQuestionByQuery(TestQuestionQuery query){
 		query.dealWith();
 		Integer result = testQuestionMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<TestQuestion> findTestQuestionByIds(List<Integer> ids){
 		List<TestQuestion> result = testQuestionMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestQuestion testQuestion : result) {
				testQuestion.dealWith();
			}
		}
		return result;
 	}
 	
}	